/******************************************************************
 * Title: scrunch.sc
 * Author:  Brian Peck
 * Date: Spring 2011
 * Description: Specification model for scrunch (in DES)
 *****************************************************************/
#include <stdio.h>
import "i_receiver";
import "i_sender";

behavior desScrunch(i_receiver ir, i_sender is)
{
  const char* bName = "desScrunch";
  void main(void) {
    unsigned long outofData[2];
    unsigned long intoData[2];
    unsigned char * outof;
    unsigned long * into;

    while (1) {
      outof = (unsigned char*)outofData;
      into = intoData;

      ir.receive(&outofData[0], sizeof(unsigned long));
      ir.receive(&outofData[1], sizeof(unsigned long));

      printf("%s: Received block[0]: 0x%lx, block[2]: 0x%lx\n", bName, outofData[0], outofData[1]);

      *into      = (*outof++ & 0xffL) << 24;
      *into     |= (*outof++ & 0xffL) << 16;
      *into     |= (*outof++ & 0xffL) << 8;
      *into++   |= (*outof++ & 0xffL);
      *into      = (*outof++ & 0xffL) << 24;
      *into     |= (*outof++ & 0xffL) << 16;
      *into     |= (*outof++ & 0xffL) << 8;
      *into     |= (*outof   & 0xffL);

      printf("%s: Sending block[0]: 0x%lx, block[2]: 0x%lx\n", bName, into[0], into[1]);

      is.send(&into[0], sizeof(unsigned long));
      is.send(&into[1], sizeof(unsigned long));
    }
  } // end main
};// end behavior scrunch
